<template>
  <el-radio-group v-model="icon">
    <div class="icon-list">
      <div class="item" v-for="(i, index) in iconList" :key="index">
        <el-radio :label="i.label"><component class="icon" :is="i.label"></component></el-radio>
      </div>
    </div>
  </el-radio-group>
</template>

<script setup name="x-icon">
import {onMounted, ref} from "vue";
import * as ElIcons from "@element-plus/icons-vue";
onMounted(() => {
  initIconList()
})

let iconList = ref([])
let icon = ref("")

const initIconList = () => {
  let ElIconsObj = ElIcons
  for (const name in ElIconsObj) {
    iconList.value.push({label: name, value: name})
  }
}

const getIcon = () => {
  return icon.value
}

defineExpose({ getIcon })
</script>

<style scoped lang="less">
.icon-list {
  width: 100%;
  display: flex;
  justify-content: flex-start;
  align-items: flex-start;
  flex-wrap: wrap;

  .item {
    width: 10%;
    height: 60px;
    display: flex;
    justify-content: center;
    align-items: center;

    .icon {
      width: 30px;
      height: 30px;
    }
  }
}
</style>